﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utilities
{
    public static class Commands
    {
        public static void checkFor(string message, Dictionary<string, Delegate> commands, out bool contains)
        {

            if (commands.ContainsKey(message))
            {
                contains = true;
                commands[message].DynamicInvoke();
            }
            else
            {
                contains = false;
            }
        }

        public static void checkWithParam(string message, Dictionary<string, Delegate> paramCommands, out bool contains)
        {
            contains = false;
            //if msg starts with any of key values of paramCommands -> dynamic invoke with parameter - rest of string
            string commandKey = (from param in paramCommands
                                 where message.StartsWith(param.Key, StringComparison.OrdinalIgnoreCase)
                                 select (param.Key)).FirstOrDefault();

            if (commandKey != null)
            {
                contains = true;
                string msgContent = message.Substring(commandKey.Length);
                paramCommands[commandKey].DynamicInvoke(msgContent);
            }

        }
    }
}
